<?php

/**
 * ECSHOP 首页文件
 * ============================================================================
 * * 版权所有 2005-2016 上海商创网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecmoban.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: index.php 17217 2011-01-19 06:29:08Z liubo $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/../includes/init.php');

$string = file_get_contents('result.txt');

$province_list = json_decode($string, true);

$insert_id = array();

//省份
foreach($province_list as $province=>$city_list){
    $data = array('region_id'=>NULL, 'parent_id'=>1, 'region_name'=>$province, 'region_type'=>1);
    $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('region_upload'), $data, 'INSERT');
    $insert_id[$province] = $GLOBALS['db']->insert_id();
    //城市
    foreach($city_list as $city=>$district_list){
        $data = array('region_id'=>NULL, 'parent_id'=>$insert_id[$province], 'region_name'=>$city, 'region_type'=>2);
        $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('region_upload'), $data, 'INSERT');
        $insert_id[$city] = $GLOBALS['db']->insert_id();
        //地区
        foreach($district_list as $district=>$street_list){
            $data = array('region_id'=>NULL, 'parent_id'=>$insert_id[$city], 'region_name'=>$district, 'region_type'=>3);
            $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('region_upload'), $data, 'INSERT');
            $insert_id[$district] = $GLOBALS['db']->insert_id();
            //街道
            foreach($street_list as $street=>$town_list){
                $data = array('region_id'=>NULL, 'parent_id'=>$insert_id[$district], 'region_name'=>$street, 'region_type'=>4);
                $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('region_upload'), $data, 'INSERT');
            }
        }
    }
}

echo "执行完毕";

?>